<?php
include ('inc/common.inc.php');
include (NCG_DLL.'page.class.php');

// get the keyword
$keyword = (isset($_GET['group']) && !empty($_GET['group'])) ? trim($_GET['group']) : "请输入组织或关键词";

//if keywords have been set, start to search group

$_GET['group'] = trim($_GET['group']);

if(isset($_GET['group']) && !empty($_GET['group']))
{
	$total = $db->num_rows($db->query("SELECT * FROM `{$pre}groupinfo` WHERE `groupname` like '%{$_GET['group']}%'"));
	$current_page = (isset($_GET['page']) && !empty($_GET['page'])) ? intval($_GET['page']) : 1;
	$fpage = new page($total,$current_page,3);
	$pageInfo = $fpage->getPageInfo();
	$sql="SELECT * FROM `{$pre}groupinfo` WHERE `groupname` like '%{$_GET['group']}%' LIMIT {$pageInfo['row_offset']}, {$pageInfo['row_num']}";
	$rst = $db->query($sql);
	$arr = array();
	while($row = $db->fetch_array($rst))
	{
		$sql="SELECT * FROM `{$pre}userinfo_basic` WHERE `groupid`={$row['id']}";
		$row['logo'] = 'files/grouplogo/'.$row['id'].'.jpg';
		$row['groupname'] = preg_replace("/{$_GET['group']}/","<font color=red>{$_GET['group']}</font>",$row['groupname']);
		$row['num'] = $db->num_rows($db->query($sql));
		$arr[] = $row;
	}
	$notice = "共有{$total}个结果，";
}
else
{
	$total = $db->num_rows($db->query("SELECT * FROM `{$pre}groupinfo`"));
	$current_page = (isset($_GET['page']) && !empty($_GET['page'])) ? intval($_GET['page']) : 1;
	$fpage = new page($total,$current_page,3);
	$pageInfo = $fpage->getPageInfo();
	$sql="SELECT * FROM `{$pre}groupinfo` LIMIT {$pageInfo['row_offset']}, {$pageInfo['row_num']}";
	$rst = $db->query($sql);
	$arr = array();
	while($row = $db->fetch_array($rst))
	{
		$sql="SELECT * FROM `{$pre}userinfo_basic` WHERE `groupid`={$row['id']}";
		$row['logo'] = 'files/grouplogo/'.$row['id'].'.jpg';
		$row['num'] = $db->num_rows($db->query($sql));
		$arr[] = $row;
	}
	$notice = "共有{$total}个组织，";
}
include template('search.html');
?>
